package com.bosssoft.ecds.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.bosssoft.ecds.entity.dto.SentBillDto;
import com.bosssoft.ecds.entity.po.UbeStockFinanceapplyPO;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 张东海
 * @date 2020/8/20
 * @description 单位端RabbitMQ监听服务，用于监听并接收来自财政端的
 *               票据申领信息记录反馈，以同步票据申领信息记录的状态，
 *               同时接收票据申领审核通过时，来自财政端的有效合法票号段
 */
@Service
public class ProducerService {

    @Resource
    UbeStockFinanceapplyServiceImpl ubeStockFinanceapplyService;

    @Resource
    UabAgenBillServiceImpl uabAgenBillService;

    @RabbitListener(queues = "fbQ")
    public void receive(UbeStockFinanceapplyPO financeapplyCheckPO){
        UbeStockFinanceapplyPO financeapplyPO = new UbeStockFinanceapplyPO();
        BeanUtil.copyProperties(financeapplyCheckPO,financeapplyPO);
        ubeStockFinanceapplyService.update(financeapplyPO);
    }

    @RabbitListener(queues = "billQ")
    public void receive(List<SentBillDto> sentBillDtos){
        for (SentBillDto sentBillDto : sentBillDtos) {
            uabAgenBillService.saveBatch(Integer.parseInt(sentBillDto.getBillNo1()),
                    Integer.parseInt(sentBillDto.getBillNo2()));
        }
    }
}
